<template>
  <div class="relative swiper_view">
    <van-swipe
      :initial-swipe="initialSwipe"
      class="my-swipe"
      :autoplay="3000"
      :show-indicators="false"
      @change="onChange">
      <van-swipe-item v-for="item in imgList" :key="item.id">
        <img class="img" :src="item.url" alt="" />
      </van-swipe-item>
    </van-swipe>
    <div class="indicators_view">
      <div
        v-for="(item, index) in imgList"
        :key="item.id"
        :class="index === initialSwipe ? 'active_indicators' : 'indicators'"></div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  const imgList = ref<any>([
    { id: 1, url: 'https://imgs.nexbie.com/uploads/7d20fd82131946b0945c7e62c7f50552.webp' },
    { id: 2, url: 'https://imgs.nexbie.com/uploads/3983f3c844304e4081f7dce28faafa89.webp' },
    { id: 3, url: 'https://imgs.nexbie.com/uploads/3aac168cda9c4d379d2b7a6b69d8ccfa.webp' },
  ]);

  const initialSwipe = ref<number>(0);
  const onChange = (index: number) => {
    initialSwipe.value = index;
  };
</script>

<style scoped lang="scss">
  .swiper_view {
    overflow: hidden;
    width: 100%;
  }
  .indicators_view {
    position: absolute;
    bottom: 0;
    padding: 8px 0;
    display: flex;
    gap: 4px;
    justify-content: center;
    width: 100%;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.32) 0%, rgba(0, 0, 0, 0) 100%);
  }
  .indicators {
    width: 12px;
    height: 2px;
    border-radius: 1px;
    background: rgba(255, 255, 255, 0.2);
  }
  .active_indicators {
    width: 12px;
    height: 2px;
    border-radius: 1px;
    background: rgba(255, 255, 255, 0.8);
  }

  .my-swipe .van-swipe-item {
    width: 100%;
    height: 127px;
    border-radius: 8px;
    overflow: hidden;
    .img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
</style>
